<html>
<head>
	<LINK REL=StyleSheet HREF="/flot/style.css" TYPE="text/css" MEDIA=screen>
	
	<script language="javascript" type="text/javascript" src="/flot/jquery.js"></script>
	<script language="javascript" type="text/javascript" src="/flot/jquery.flot.js"></script>
	<script language="javascript" type="text/javascript" src="/flot/jquery.flot.selection.js"></script>
	
</head>
<body>
	<div id="plots">
		<div class="title">Temperature vs. Time</div>
		<div id="flot_T" class="plot"></div>
		<div class="title">Humidity vs. Time</div>
		<div id="flot_H" class="plot"></div>
		<div class="title">Light vs. Time</div>
		<div id="flot_L1" class="plot"></div>
		
	</div>
	
	<div id=battery>
		<div class="title">Xantrex Variables</div>
		<div>DC Side: V=120 V I=12A SOC=34%</div>
		<div>AC Side: V=120 V I=12A</div>
		<div>NiZn: V=120 V I=12A SOC=22%</div>
		<table>
			<tr><td>TPb1</td><td>TPb1</td><td>TPb1</td><td>TPb1</td></tr>
			<tr><td>78</td><td>81</td><td>75</td><td>73</td></tr>
		</table>
		<table>
			<tr><td>TNiZn1</td><td>TNiZn2</td><td>TNiZn3</td><td>TNiZn4</td></tr>
			<tr><td>78</td><td>81</td><td>75</td><td>73</td></tr>
		</table>
	</div>
	
	<button id="clearSelection">Clear Selection</button>
</body>

<script src="/flot/build_dom.js"></script>
<script src="/flot/functions.js"></script> 
<script>

stuffs = $("[id^=flot_]")
field_json = {'time':1}

for (var i = 0; i < stuffs.length; i++)
{
	//console.log(thing.id)
	if (stuffs[i].id != undefined) 
	{
		console.log(stuffs[i].id)
		field_json[stuffs[i].id.replace("flot_","")] = 1
	}
}

foo = window.location.pathname.split("/")
db_to_get = "shortball"
grabData({collection:db_to_get,query:{},fields:field_json})
stuff_to_omit = ['time','id']

for (name in field_json)
{
	if (stuff_to_omit.indexOf(name) == -1)
	{
		$("#flot_"+name).bind("plotselected",function (event, ranges) {
	
			out_min= ranges.xaxis.from;
			out_max = ranges.xaxis.to;	
			alert(out_min + " " + out_max)
			grabData({collection:db_to_get,query:{'time':{'$gt':out_min,'$lt':out_max}},fields:field_json})
	
		});
	}
}

setInterval(function(){grabData({collection:db_to_get,query:{},fields:field_json})},10000)
$("#clearSelection").click(function (){grabData({collection:db_to_get,query:{},fields:field_json})});

</script>
</html>